<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    for (var i = 0; i < 3; i++) { // var和Let会导致结果不同
        setTimeout(() => {
            console.log(i) // 3 3 3
        })
    }

    // 如何显示 0 1 2
    for (var i = 0; i < 3; i++) {
        (function () {
            console.log(i) // 0 1 2
        })()
    }



</script>
</body>
</html>